package com.fr.base;

import com.fr.base.core.FRCoreContext;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import java.util.Comparator;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ClassComparator
  implements FComparator, XMLable
{
  private String className = "";
  private transient Comparator comparator = null;

  public ClassComparator()
  {
  }

  public ClassComparator(String paramString)
  {
    this.className = paramString;
  }

  public String getClassName()
  {
    return this.className;
  }

  public void setClassName(String paramString)
  {
    this.className = paramString;
  }

  public int compare(Object paramObject1, Object paramObject2)
  {
    if (this.comparator == null)
      try
      {
        this.comparator = ((Comparator)FRCoreContext.classForName(this.className).newInstance());
      }
      catch (Exception localException)
      {
        FRContext.getLogger().log(Level.WARNING, localException.getMessage(), localException);
      }
    return this.comparator.compare(paramObject1, paramObject2);
  }

  public String toString()
  {
    return "ClassComparator[Class:" + getClassName() + "]";
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return new ClassComparator(getClassName());
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("ClassComparatorAttr")))
    {
      String str;
      if ((str = paramXMLableReader.getAttr("className")) != null)
        setClassName(str);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("ClassComparatorAttr").attr("className", getClassName()).end();
  }
}